package com.zhouyu.exampleThread.threadTest;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;

import lombok.Data;
import lombok.extern.log4j.Log4j2;

/**
 * @Description:
 */
@Log4j2
@Data
public class Productor extends Thread {
  private CountingStar countingStar;
  private Lock lock;
  private Condition conditionPro;
  private Condition conditionConsu;

  @Override
  public void run() {
    while (true){
      try {
        lock.lock();
        if((countingStar.size()>100)){
          log.info("停止生产,叫醒消费者");
          conditionPro.await();
        }
        countingStar.add();
        conditionConsu.signal();
      } catch (InterruptedException e) {
        e.printStackTrace();
      } finally {
        lock.unlock();
      }
    }
  }
}
